package com.it.Controller;

import com.it.Service.PassengerService;
import com.it.pojo.Passenger;
import com.it.pojo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = "*") // 解决跨域问题，允许所有来源访问，实际中可配置具体域名
@RestController
public class PassengerController {
    private static final Logger log = LoggerFactory.getLogger(PassengerController.class);
    @Autowired
    private PassengerService passengerService;

    //获取用户绑定的身份证信息
    @GetMapping("/passenger/{username}")
    public Result getPassenger(@PathVariable String username) {
        List<Passenger> passengers=passengerService.getPassenger(username);
        return Result.success(passengers);
    }

    //获取用户的实名身份信息
    @GetMapping("/identity/{username}")
    public Result getIdentity(@PathVariable String username) {
        Passenger identity=passengerService.getIdentity(username);
        return Result.success(identity);
    }

    @PostMapping("/passenger/{username}")
    public Result addPassenger(@RequestBody Passenger passenger,@PathVariable String username){
        log.info("{},{}",passenger,username);
        passengerService.addPassenger(passenger,username);
        return Result.success();
    }

    @DeleteMapping("/passenger/{idNumber}")
    public Result deletePassenger(@PathVariable String idNumber ){
        passengerService.deletePassenger(idNumber);
        return Result.success();
    }

    //数据回显
    @GetMapping("/passengerById/{idNumber}")
    public Result getPassengerById(@PathVariable String idNumber){
        Passenger passenger=passengerService.getPassengerById(idNumber);
        return Result.success(passenger);
    }

    @PutMapping("/passenger")
    public Result updatePassenger(@RequestBody Passenger passenger){
        passengerService.updatePassenger(passenger);
        return Result.success();
    }
}
